package com.zeroxml.cms.web.action.cms;

import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import com.zeroxml.cms.service.IArticleService;
import com.zeroxml.cms.service.ICatalogService;
import com.zeroxml.cms.bo.Article;
import com.zeroxml.cms.bo.Catalog;
import com.zeroxml.cms.web.action.BaseAction;
import com.wyvoid.core.persistent.hibernate.HibernatePage;

import java.util.List;

/**
 * User: cjp
 * Date: 2007-9-16
 * Time: 21:51:51
 */
@UrlBinding("/openSource.do")
public class OpenSourceAction extends BaseAction {
    @SpringBean
    IArticleService articleService;
    @SpringBean
    ICatalogService catalogService;
    HibernatePage<Article> articles;
    List catalogList;
    long catalogId;
    private int curPage;

    public void setArticleService(IArticleService articleService) {
        this.articleService = articleService;
    }

    public HibernatePage<Article> getArticles() {
        return articles;
    }

    public void setCatalogId(long catalogId) {
        this.catalogId = catalogId;
    }

    public List getCatalogList() {
        return catalogList;
    }

    public void setCatalogList(List catalogList) {
        this.catalogList = catalogList;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    @DefaultHandler
    public Resolution openSource() {
        Catalog catalog = catalogService.getCatalog("openSource");
        if (catalogId <= 0) {
            catalogId = catalog.getId();
            articles = new HibernatePage<Article>(articleService.getRecommedArticles(catalogId), 1, 100, 100);
        } else {
            int pageSize = 20;
            articles = articleService.findArticles(catalogId, null, curPage, pageSize);
        }
        catalogList = catalogService.getCatalogList(catalog.getId());

        return getCmsResolution("openSource/openSource");
    }
}
